package cate.game.gm.sub;

import cate.common.table.d.GDOperation;
import cate.game.GameBody;
import cate.game.mail.po.MailBuilder;
import cate.game.role.Role;
import cate.game.role.mail.Mail;
import cp.solution.business.gm.dto.VipRebateCmd;
import easy.java.practice.errorcode.EcException;
import easy.java.practice.errorcode.EcResult;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class VipRebateForGm {

    public static EcResult exe(GameBody game, VipRebateCmd cmd) {
        log.info("收到console发出的VIP返利的请求 cmd={}", cmd);
        Role role = game.role.getRole(cmd.getRoleId());
        if(role == null) {
            throw new EcException("角色不存在("+cmd.getRoleId()+")");
        }
        Mail mail = new MailBuilder()
                .setTitle(cmd.getConf().getMailTitle())
                .setContent(cmd.getConf().getMailContent())
                .setRewardConf(cmd.getConf().getReward())
                .setOperation(GDOperation.VIP_REBATE)
                .setOperationSub(cmd.getConf().getRmb()).build();
        role.getMail().add(mail);
        EcResult er = new EcResult().success("完美执行 " + role);
        return er;
    }
}
